package com.xjtu.platform.user.consultor.addconsult.dao;

import com.xjtu.platform.user.consultor.addconsult.AdditionDto;
import com.xjtu.platform.user.consultor.addconsult.RecordModel1;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.util.List;

@Mapper
public interface AddConsultDao {


    @Select("select user.user_id,user.user_name,user.user_age,user.email , consult.count_num as count, first_visit.visit_id,first_visit.status ,consult.state \n" +
            "from user,first_visit,consult\n" +
            "Inner join (select visit_id,max(count_num) as count from consult group by visit_id ) as d\n" +
            "where first_visit.visiter_id = #{user_id} and consult.visit_id = first_visit.visit_id and user.user_id = first_visit.student_id and consult.count_num>7  and first_visit.visit_id = d.visit_id and consult.count_num = d.count\n" +
            "order by visit_id ")
    List<RecordModel1> getInfo(@Param("user_id") String user_id);

    @Insert("insert into additional_apply(state,apply_id,visit_id,count_num,comment) value (#{state},#{apply_id},#{visit_id},#{count},#{comment})")
    void addConsult(AdditionDto dto);

    @Select("select count(*) from additional_apply")
    int Count();

    @Select("select state from additional_apply where additional_apply.visit_id = #{visit_id} and state = 0")
    Integer checkAdd(AdditionDto dto);


    @Select("select max(count_num) from additional_apply where additional_apply.visit_id = #{visit_id} ")
    Integer getCount(AdditionDto dto);

    @Select("select state from additional_apply where visit_id = #{visit_id} and count_num = #{count}")
    Integer getResult(AdditionDto dto);
}
